#
# Copyright (C) 2021 Codership Oy <info@codership.com>
#

#
# Note: Files under ../src are inside wsrep-API submodule, so
# these tests won't compile unless the submodule has been
# initialized/updated.
#

Import('check_env', 'GALERA_VER', 'GALERA_REV')

# make sure API version is present once in GALERA_VER string
API = '25.'
GALERA_VER = API + GALERA_VER.replace(API, '')

# Clone environment as we need to tune compilation flags
env = check_env.Clone()

env.Replace(CPPFLAGS = '-D_XOPEN_SOURCE=600') # for strdup()
env.Append(CPPFLAGS = ' -DWSREP_PROVIDER=\\"' + File('#/libgalera_smm.so').abspath + '\\"')
env.Append(CPPFLAGS = ' -DGALERA_VERSION=\\"' + GALERA_VER + '\\"')
env.Append(CPPFLAGS = ' -DGALERA_GIT_REVISION=\\"' + GALERA_REV + '\\"')
env.Append(CPPPATH = ['#/galerautils/src'])
env.Replace(LIBS = 'dl')

wsrep_test_sources = Split('''
                           wsrep_loader_test.c
                           ../src/wsrep_loader.c
                           ../src/wsrep_dummy.c
                           ''')

wsrep_test = env.Program(target = 'wsrep_test', source = wsrep_test_sources)
Depends(wsrep_test, '#/libgalera_smm.so')

stamp = "wsrep_test.passed"
env.Test(stamp, wsrep_test)
env.Alias("test", stamp)

Clean(wsrep_test, [stamp])
